home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Suzy B Software 2
/
Suzy B Software CD-ROM 2 (1994).iso
/
new_file
/
extras
/
games
/
text_adv
/
adven_cr
/
basic.adi
< prev
next >
Wrap
Text File
|
1985-11-19
|
10KB
|
404 lines
; This is the simple runtime package
; by David Betz
; January 11, 1985
; ********************
; PROPERTY DEFINITIONS
; ********************
; These properties will be used for connections between locations
(property
north ; the location to the north
south ; the location to the south
east ; the location to the east
west ; the location to the west
up ; the location above
down) ; the location below
; Basic object properties
(property
initial-location ; the initial location of a "thing"
description ; the "long" description of a location
short-description) ; the "short" description of a location
; Connection properties
(property
parent ; the parent of an object
sibling ; the next sibling of an object
child) ; the first child of an object
; **********************
; VOCABULARY DEFINITIONS
; **********************
; Some abbreviations for common commands
(synonym north n)
(synonym south s)
(synonym east e)
(synonym west w)
(synonym inventory i)
; Define the basic vocabulary
(conjunction and)
(article the that)
; ********************
; VARIABLE DEFINITIONS
; ********************
(variable
curloc ; the location of the player character
%actor ; the actor object
%dobject ; the direct object
%iobject) ; the indirect object
; ************************
; OBJECT CLASS DEFINITIONS
; ************************
; The "basic-thing" class
(object basic-thing
(property
parent nil ; the parent of this object
sibling nil)) ; the next sibling of this object
; The "location" object class
(object location
(property
child nil ; the first object in this location
visited nil)) ; has the player been here yet?
; The "actor" class
(basic-thing actor
(property
child nil)) ; the first "thing" carried by this actor
; The "thing" class (things that can be taken)
(basic-thing thing
(class-property
takeable t))
; The "stationary-thing" class (things that can't be moved)
(basic-thing stationary-thing)
; *********************
; CONNECTION PRIMITIVES
; *********************
; Connect an object to a parent
(define (connect p c)
(setp c parent p)
(setp c sibling (getp p child))
(setp p child c))
; Connect all objects to their initial parents
(define (connect-all &aux obj maxp1 par)
(setq obj 1)
(setq maxp1 (+ $ocount 1))
(while (< obj maxp1)
(if (setq par (getp obj initial-location))
(connect par obj))
(setq obj (+ obj 1))))
; Disconnect an object from its current parent
(define (disconnect obj &aux this prev)
(setq this (getp (getp obj parent) child))
(setq prev nil)
(while this
(if (= this obj)
(progn
(if prev
(setp prev sibling (getp this sibling))
(setp (getp this parent) child (getp this sibling)))
(setp this parent nil)
(return)))
(setq prev this)
(setq this (getp this sibling))))
; Disconnect and reconnect an object to a new parent
(define (putin c p)
(if (getp c parent)
(disconnect c))
(connect p c))
; Check to see if an object is the child of another object
(define (isin? c p)
(= (getp c parent) p))
; ***********************
; MISCELLANEOUS FUNCTIONS
; ***********************
; Cause an object to travel an a specified direction
(define (travel obj dir &aux loc)
(if (and (setq loc (getp obj parent))
(setq loc (getp loc dir)))
(progn
(disconnect obj)
(connect loc obj)
T)))
; Print the contents of an object (used by "look")
(define (print-contents obj prop &aux desc)
(setq obj (getp obj child))
(while obj
(if (setq desc (getp obj prop))
(progn
(print " ")
(print desc)))
(setq obj (getp obj sibling))))
; List the contents of an object (used for "inventory")
(define (list-contents obj prop &aux desc)
(setq obj (getp obj child))
(while obj
(if (setq desc (getp obj prop))
(progn
(print "\t")
(print desc)
(terpri)))
(setq obj (getp obj sibling))))
; Complain about a noun phrase
(define (complain head n tail)
(print head)
(print-noun n)
(print tail)
(abort))
; Find an object in a location
(define (findobject loc n &aux this found)
(setq this (getp loc child))
(setq found nil)
(while this
(if (match this n)
(if found
(complain "I don't know which " n " you mean!\n")
(setq found this)))
(setq this (getp this sibling)))
found)
; Find an object in the player's current location
; (or in the player's inventory)
(define (in-location n &aux obj)
(if (or (setq obj (findobject curloc n))
(setq obj (findobject %actor n)))
obj
(complain "I don't see a " n " here!\n")))
; Find an object in the player's inventory
; (or in the player's current location)
(define (in-pocket n &aux obj)
(if (or (setq obj (findobject %actor n))
(setq obj (findobject curloc n)))
obj
(complain "You don't have a " n "!\n")))
; Get the short description of an object
; (or the long description if there is no short one)
(define (get-short-description loc &aux dsc)
(if (setq dsc (getp loc short-description))
dsc
(getp loc description)))
; Print the long description of a location
(define (print-long-description loc)
(print (getp loc description))
(print-contents loc description))
; Look around a location
; (print the long description if the player hasn't been here before
; otherwise, print the short description)
(define (look-around loc)
(if (getp loc visited)
(print (get-short-description loc))
(print-long-description loc))
(setp loc visited T)
(terpri))
; Cause an actor to move in the specified direction
(define (move dir)
(if (not (travel %actor dir))
(print "There is no exit in that direction.\n")))
; Cause an actor to take an object
(define (take-it act obj)
(putin obj act))
; Cause an actor to drop an object
(define (drop-it act obj)
(putin obj curloc))
; ***************
; ACTION DEFAULTS
; ***************
(default
(actor optional))
; ******************
; ACTION DEFINITIONS
; ******************
(action look
(verb look)
(code
(print-long-description curloc)
(terpri)))
(action take
(verb take get (pick up))
(direct-object)
(code
(setq %dobject (in-location $dobject))
(if (getp %dobject takeable)
(progn
(if (isin? %dobject %actor)
(complain "You are already carrying the " $dobject "!\n"))
(take-it %actor %dobject)
(print-noun $dobject)
(print " taken.\n"))
(complain "You can't take the " $dobject "!\n"))))
(action take-err
(verb take get (pick up))
(code
(print "Take what?\n")))
(action drop
(verb drop (put down))
(direct-object)
(code
(setq %dobject (in-pocket $dobject))
(if (isin? %dobject %actor)
(progn
(drop-it %actor %dobject)
(print-noun $dobject)
(print " dropped.\n"))
(complain "You aren't carrying the " $dobject "!\n"))))
(action drop-err
(verb drop (put down))
(code
(print "Drop what?\n")))
(action give
(verb give)
(direct-object)
(preposition to)
(indirect-object)
(code
(setq %dobject (in-pocket $dobject))
(setq %iobject (in-location $iobject))
(if (isin? %dobject %actor)
(progn
(drop-it %actor %dobject)
(take-it %iobject %dobject)
(print-noun $dobject)
(print " given.\n"))
(complain "You aren't carrying the " $dobject "!\n"))))
(action give-err
(verb give)
(direct-object optional)
(code
(if $dobject
(complain "Give the " $dobject " to who?\n"))
(print "Give what?\n")))
(action inventory
(verb inventory)
(code
(cond ((getp %actor child)
(print "You are carrying:\n")
(list-contents %actor short-description))
(T (print "You are empty-handed.\n")))))
; *********************
; GAME CONTROL COMMANDS
; *********************
(action save
(verb save)
(code
(save)))
(action restore
(verb restore)
(code
(restore)))
(action restart
(verb restart)
(code
(restart)))
(action quit
(verb quit)
(code
(print "Are you sure you want to quit? ")
(if (yes-or-no)
(exit))))
; **************
; TRAVEL ACTIONS
; **************
(action go-north
(verb north (go north))
(code
(move north)))
(action go-south
(verb south (go south))
(code
(move south)))
(action go-east
(verb east (go east))
(code
(move east)))
(action go-west
(verb west (go west))
(code
(move west)))
(action go-up
(verb up (go up))
(code
(move up)))
(action go-down
(verb down (go down))
(code
(move down)))
; *******************
; HANDLER DEFINITIONS
; *******************
(init
(connect-all)
(print welcome)
(setq curloc nil))
(update
(if (not (= (getp adventurer parent) curloc))
(progn
(setq curloc (getp adventurer parent))
(look-around curloc))))
(before
(setq %actor adventurer)
(if $actor
(progn
(setq %actor (in-location $actor))
(if (not (= (class %actor) actor))
(complain "You can't talk to a " $actor "!\n")))))